// This file is an attempt to create a Circle Overlay for google maps v3
// it is really a many-pointed polygon, but look smooth enough to be a circle.
var CircleOverlay = function(latLng, radius, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity) {
	this.latLng = latLng;
	this.radius = radius;
	this.strokeColor = strokeColor;
	this.strokeWidth = strokeWidth;
	this.strokeOpacity = strokeOpacity;
	this.fillColor = fillColor;
	this.fillOpacity = fillOpacity;
	this.polygon;
	
	this.draw();
}


// Calculate all the points and draw them
CircleOverlay.prototype.draw = function(force) {
	var d2r = Math.PI / 180;
	circleLatLngs = new google.maps.MVCArray();
	var circleLat = this.radius * 0.014483;  // Convert statute miles into degrees latitude
	var circleLng = circleLat; // / Math.cos(this.latLng.lat() * d2r);
	var numPoints = 40;
	
	// 2PI = 360 degrees, +1 so that the end points meet
	for (var i = 0; i < numPoints + 1; i++) { 
		var theta = Math.PI * (i / (numPoints / 2)); 
		var vertexLat = this.latLng.lat() + (circleLat * Math.sin(theta)); 
		var vertexLng = this.latLng.lng() + (circleLng * Math.cos(theta));
		var vertextLatLng = new google.maps.LatLng(vertexLat, vertexLng);
		circleLatLngs.push(vertextLatLng); 
	}
	
	// create the line object
	polylineOptions = {
			map: map,
			strokeColor: "#000000",
			strokeOpacity: 0.8,
			strokeWeight: 2,
			path: circleLatLngs
	}
	this.polygon = new google.maps.Polyline(polylineOptions);
}

